<%@page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
<%@include file="/wx/page/session.jsp"%>
<c:set var="userId" value="${param.userId}" />
<c:set var="deptId" value="${param.deptId}" />
<c:set var="deptCode" value="${param.deptCode}" />
<c:set var="deptParentId" value="${param.deptParentId}" />
<c:set var="taskId" value="${param.taskId}" />
<c:set var="taskCostPrice" value="${param.taskCostPrice}" />
<c:set var="taskType" value="${param.taskType}" />
<c:set var="taskState" value="${param.taskState}" />
<c:set var="billId" value="${param.billId}" />
<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no, width=device-width">
    <meta content="yes" name="apple-mobile-web-app-capable">
    <meta content="black" name="apple-mobile-web-app-status-bar-style">
    <title>打印提货单</title>
    <script type="text/javascript" src="${ctx}/dwr/engine.js"></script>
    <script type="text/javascript" src="${ctx}/dwr/util.js"></script>
    <script type="text/javascript" src="${ctx}/dwr/interface/BillService.js"></script>
    <script type="text/javascript" src="${ctx}/dwr/interface/TruckService.js"></script>
    <script type="text/javascript" src="${ctx}/dwr/interface/TaskService.js"></script>
    <script type="text/javascript" src="${ctx}/dwr/interface/UserService.js"></script>
    <script type="text/javascript" src="${ctx}/dwr/interface/DeptService.js"></script>
    <script type="text/javascript" src="${ctx}/wx/js/alert.js"></script>
    <script type="text/javascript" src="${ctx}/wx/js/qrcode.js"></script>
</head>
<body>
<input type="hidden" id="printNum" name="printNum" value="1">
<input type="hidden" id="deptPrintSn" name="deptPrintSn">
<input type="hidden" id="url" name="url" value="http://iwooch.cn/ant/wx/page/bill_print_detail.jsp?userId=${userId}&deptId=${deptId}&deptCode=${deptCode}&deptParentId=${deptParentId}&billId=${billId}">
<img id="deptLogo" width="50" height="50" src="" >
<input type="button" value="打印" style="position: absolute;top: 20px; right: 0;" onclick="printBill()">
<br>
<table>
    <tr>
        <td align="center" style="font-weight: bold">
            <span id="deptName"></span>货运协议
        </td>
    </tr>
    <tr>
        <td>
            <br>
        </td>
    </tr>
    <tr>
        <td>
            甲方(托运方)：<span id="taskSenderUserName"></span>&nbsp;<span id="taskSenderUserMobile"></span>
        </td>
    </tr>
    <tr>
        <td>
            乙方(承运方)：<span id="truckUserName"></span>&nbsp;<span id="truckMobile"></span>
        </td>
    </tr>
    <tr>
        <td>
            车主籍贯：<span id="truckNative"></span>
        </td>
    </tr>
    <tr>
        <td>
            提货单号：<span id="billCode"></span>
        </td>
    </tr>
    <tr>
        <td>
            车牌号：<span id="truckPlates"></span>
        </td>
    </tr>
    <tr>
        <td>经协商甲、乙双方自愿达成如下协议：</td>
    </tr>
    <tr>
        <td>
            甲方委托乙方承运货物 <span id="taskGoodsStandard"></span>，数量 <span id="truckNum"></span> 件，由 <span id="taskLoadingArea"></span>&nbsp;<span id="taskLoadingAddress"></span>&nbsp;至&nbsp;<span id="taskUnloadingArea"></span>&nbsp;<span id="taskUnloadingAddress"></span>。全程运费 <span id="taskFreightPrice"></span> 元／吨，运费支付方式货到 <span id="taskPayWay"></span> 付清。
        </td>
    </tr>
    <tr>
        <td>
            备注：<span id="taskRemark"></span>
        </td>
    </tr>
    <tr>
        <td align="center">更多协议条款，请点击或扫描二维码查看</td>
    </tr>
    <tr>
        <td align="center">
            <a href="http://iwooch.cn/ant/wx/page/bill_print_detail.jsp?userId=${userId}&deptId=${deptId}&deptCode=${deptCode}&deptParentId=${deptParentId}&billId=${billId}">
                <div id="qrcode">
                </div>
            </a>
        </td>
    </tr>
    <tr>
        <td>
            甲方经办人：&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
            乙方经办人：
        </td>
    </tr>
    <tr>
        <td>
            中介：<span id="deptName1"></span>
        </td>
    </tr>
    <tr>
        <td>
            地址：<span id="deptAddress"></span>
        </td>
    </tr>
    <tr>
        <td>
            经办人：
        </td>
    </tr>
    <tr>
        <td align="right">
            <span id="currentDate"></span>
        </td>
    </tr>
    <tr>
        <td align="center" style="font-weight: bold">
            客服电话：<span id="staffUserMobile"></span>
        </td>
    </tr>
</table>
</body>
</html>
<script type="text/javascript">
    DeptService.getCurrentDate(0, "yyyy年MM月dd日", callbackGetCurrentDate);
    function callbackGetCurrentDate(currentDate) {
        dwr.util.setValue("currentDate", currentDate);
    }

    var billTruck = new BillTruck();
    billTruck.billId = "${billId}";
    BillService.selectBillTruckList(billTruck, callbackSelectBillTruckList);
    function callbackSelectBillTruckList(list) {
        var num = list.length;
        dwr.util.setValue("truckNum", num);
        billTruck = list[0];
        var truck = billTruck.truck;
        dwr.util.setValue("truckUserName", billTruck.truck.user.userName);
        dwr.util.setValue("truckMobile", billTruck.truck.user.userMobile);
        dwr.util.setValue("truckNative", truck.truckNative);
        var truckPlates = "";
        for (var i = 0; i < list.length; i++) {
            truck = list[i].truck;
            truckPlates += truck.truckPlateHeader + truck.truckPlateMiddle + truck.truckPlateCode + " ";
        }
        dwr.util.setValue("truckPlates", truckPlates);
    }

    var bill = new Bill();
    bill.billId = "${billId}";
    BillService.selectBillList(bill, callbackSelectBillList);
    function callbackSelectBillList(list) {
        var bill = list[0];
        dwr.util.setValue("billCode", bill.billCode);

        var deptId = bill.deptId;
        var dept = new Dept();
        dept.deptId = deptId;
        DeptService.selectDeptList(dept, callbackSelectDeptList);

        var taskId = bill.taskId;
        var task = new Task();
        task.taskId = taskId;
        TaskService.selectTaskList(task, callbackSelectTaskList);

        var staff = new Staff();
        staff.deptId = deptId;
        staff.staffType = 1;
        UserService.selectStaffList(staff, callbackSelectStaffist);
    }

    function callbackSelectDeptList(list) {
        var dept = list[0];
        dwr.util.setValue("deptName", dept.deptName);
        dwr.util.setValue("deptName1", dept.deptName);
        dwr.util.setValue("deptAddress", dept.deptAddress);
        dwr.util.setValue("deptPrintSn", dept.deptPrintSn);
        $("deptLogo").src = "${ctx}" + dept.deptLogo;
    }

    function callbackSelectTaskList(list) {
        var task = list[0];
        dwr.util.setValue("taskSenderUserName", task.taskSenderUserName);
        dwr.util.setValue("taskSenderUserMobile", task.taskSenderUserMobile);
        dwr.util.setValue("taskGoodsStandard", task.taskGoodsStandard);
        dwr.util.setValue("taskLoadingArea", task.taskLoadingArea);
        dwr.util.setValue("taskLoadingAddress", task.taskLoadingAddress);
        dwr.util.setValue("taskUnloadingArea", task.taskUnloadingArea);
        dwr.util.setValue("taskUnloadingAddress", task.taskUnloadingAddress);
        dwr.util.setValue("taskFreightPrice", task.taskFreightPrice);
        dwr.util.setValue("taskPayWay", task.taskPayWay);
        dwr.util.setValue("taskRemark", task.taskRemark);
    }

    function callbackSelectStaffist(list) {
        var staff = list[0];
        dwr.util.setValue("staffUserMobile", staff.user.userMobile);
    }

    window.onload =function(){
        var qrcode = new QRCode(document.getElementById("qrcode"), {
            width : 200,//设置宽高
            height : 200
        });
        qrcode.makeCode("http://iwooch.cn/ant/wx/page/bill_print_detail.jsp?userId=${userId}&deptId=${deptId}&deptCode=${deptCode}&deptParentId=${deptParentId}&billId=${billId}");
    }
    
    function printBill() {
        BillService.printBill(dwr.util.getValue("printNum"),
                dwr.util.getValue("deptPrintSn"),
                dwr.util.getValue("deptName"),
                dwr.util.getValue("deptAddress"),
                dwr.util.getValue("taskSenderUserName"),
                dwr.util.getValue("taskSenderUserMobile"),
                dwr.util.getValue("taskLoadingArea"),
                dwr.util.getValue("taskLoadingAddress"),
                dwr.util.getValue("taskUnloadingArea"),
                dwr.util.getValue("taskUnloadingAddress"),
                dwr.util.getValue("taskGoodsStandard"),
                dwr.util.getValue("taskFreightPrice"),
                dwr.util.getValue("taskPayWay"),
                dwr.util.getValue("taskRemark"),
                dwr.util.getValue("truckUserName"),
                dwr.util.getValue("truckMobile"),
                dwr.util.getValue("truckNative"),
                dwr.util.getValue("truckNum"),
                dwr.util.getValue("truckPlates"),
                dwr.util.getValue("billCode"),
                dwr.util.getValue("staffUserMobile"),
                dwr.util.getValue("url"), callbackPrintBill);
    }

    function callbackPrintBill(billPrintResult) {
        if(billPrintResult.ret == 0) {
            alert("打印完成");
            location = "${ctx}/wx/page/bill_list.jsp?userId=${userId}&deptId=${deptId}&deptCode=${deptCode}&deptParentId=${deptParentId}&taskId=${taskId}&taskType=${taskType}&taskCostPrice=${taskCostPrice}&taskState=${taskState}";
        } else {
            alert("打印失败：" + billPrintResult.msg);
        }
    }
</script>